package com.example.demo1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.demo1.entity.JumpCode;
import com.example.demo1.entity.Student;

import java.io.Serializable;

public class SettingActivity extends Activity {
    private static final String TAG = "SettingActivity->";
    public static String PARAMS_STUDENT = "params_student";
    public static String PARAMS_STUDENT_RETURN = "params_student_return";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        initData();
        initView();
    }

    private void initView() {
        findViewById(R.id.btn_data_return).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Student student = new Student("李四", 20);
                Intent intent = new Intent();
                intent.putExtra(PARAMS_STUDENT_RETURN, student);
                setResult(JumpCode.RES_SETTING, intent);
                finish();
            }
        });
    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            Serializable serializableExtra = intent.getSerializableExtra(PARAMS_STUDENT);
            if (serializableExtra instanceof Student) {
                Student student = (Student) serializableExtra;
                Log.d(TAG, "initData>>>student = " + student);
            }
        }
    }
}
